﻿using System;
using System.ComponentModel;
using System.Windows.Input;
using Foundation;
using Poet.Properties;

namespace Poet.ViewModels
{
    public class AboutViewModel : ViewModel
    {
        public AboutViewModel()
        {
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, args) => OnClosing(sender, new CancelEventArgs())));
        }

        public string ApplicationName
        {
            get { return (string) Settings.Default["ApplicationName"]; }
        }

        public int Year
        {
            get { return BuildDateTime.Year; }
        }

        public Version Version
        {
            get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; }
        }

        public DateTime BuildDateTime
        {
            get
            {
                var dateTime = new DateTime(2000, 1, 1).AddDays(Version.Build).AddSeconds(Version.Revision*2);
                if (TimeZone.IsDaylightSavingTime(dateTime, TimeZone.CurrentTimeZone.GetDaylightChanges(dateTime.Year)))
                    dateTime = dateTime.AddHours(1);
                return dateTime;
            }
        }

        public string BuildPlace
        {
            get { return (string) Settings.Default["BuildPlace"]; }
        }
    }
}
